package net.sansi.v3correctserver.service.screen;

import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiScreenDto;
import net.sansi.v3correctserver.entity.screen.ScanBoard;
import net.sansi.v3correctserver.entity.screen.Screen;
import net.sansi.v3correctserver.service.v3serverapi.V3ServerScreenApi;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fang
 * create time : 2024/11/4
 * IDE : IntelliJ IDEA
 * <p>
 * 显示屏幕服务
 */
@Service
public class ScreenService {

    @Resource
    private V3ServerScreenApi v3ServerScreenApi;

    /**
     * 获取显示屏列表
     *
     * @return 显示屏列表信息
     */
    public List<Screen> list() {
        V3ServerApiScreenDto.ScreensResp screens = v3ServerScreenApi.screens(100, 0);
        if (screens.getRequestDatas() == null || screens.getRequestDatas().isEmpty()) {
            return List.of();
        }
        return screens.getRequestDatas().stream().map(Screen::of).toList();
    }

    /**
     * 获取某个显示屏所有扫描板 + 面板信息
     *
     * @param screenId 显示屏 id
     * @return 列表
     */
    public List<ScanBoard> scanBoards(String screenId) {
        V3ServerApiScreenDto.AllStatusResp allStatus = v3ServerScreenApi.allStatus(screenId);
        List<ScanBoard> scanBoards = new ArrayList<>();
        for (V3ServerApiScreenDto.AllStatusResp.V3SendBox box : allStatus.getSendBoxs()) {
            for (V3ServerApiScreenDto.AllStatusResp.V3ScanBoard sb : box.getScanBoards()) {
                scanBoards.add(ScanBoard.of(sb));
            }
        }
        return scanBoards;
    }
}
